﻿using HRX.PayCenter.ApplicationCore.Entities;
using HRX.PayCenter.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
using UnitTests.Builders;
using Xunit;
using Xunit.Abstractions;

namespace IntegrationTests.Repositories.EFRepositoryTest
{
    public class GetOrder
    {
        private readonly EFRepository<AlipayOrderEntity> _efRepository;
        private readonly CatalogContext _catalogContext;
        private AlipayOrderBuilder OrderBuilder { get; } = new AlipayOrderBuilder();
        private readonly ITestOutputHelper _output;

        public GetOrder(ITestOutputHelper output)
        {
            _output = output;
            var dbOptions = new DbContextOptionsBuilder<CatalogContext>()
              .UseInMemoryDatabase(databaseName: "TestCatalog")
              .Options;
            _catalogContext = new CatalogContext(dbOptions);
            _efRepository = new EFRepository<AlipayOrderEntity>(_catalogContext);
        }

        [Fact]
        public void CreateAlipayOrder()
        {
            var existingOrder = OrderBuilder.WithDefaultValues();
            _catalogContext.AlipayOrders.Add(existingOrder);
            _catalogContext.SaveChanges();
            int orderId = existingOrder.Id;
            _output.WriteLine($"OrderId: {orderId}");

            var orderFromRepo = _efRepository.GetById(orderId);
            Assert.Equal(existingOrder.OrderNo, orderFromRepo.OrderNo);
        }
    }
}
